package com.beta.elephant.vo;

import com.beta.elephant.constant.ErrorCodeEnum;
import com.beta.elephant.constant.IRetCode;
import lombok.Data;

import java.io.Serializable;

/**
 * 所有请求的基本响应
 */
@Data
public abstract class BaseResp implements Serializable {
    /**
     * 响应状态码
     * 默认成功
     */
    private IRetCode result = ErrorCodeEnum.OK;

    public boolean isSucc() {
        return ErrorCodeEnum.OK.getCode().equals(result.getCode());
    }

    public <T> T retCode(IRetCode result) {
        this.result = result;
        return (T) this;
    }

    /**
     * 以整数形式返回响应状态码
     *
     * @return
     */
    public int getRetCodeInt() {
        return getResult().getCodeInt();
    }

    /**
     * 返回响应的信息
     *
     * @return
     */
    public String getRetCodeMsg() {
        return getResult().getMsg();
    }
}
